<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with for loop - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=for+loop</link>
      <pubDate>Sun, 08 Aug 2021 19:15:46 +0000</pubDate>
         <description>Tagged with for loop - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedfor+loop/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Touch Loop breaks when too many touches?</title>
      <link>https://forum.processing.org/two/discussion/22739/touch-loop-breaks-when-too-many-touches</link>
      <pubDate>Wed, 24 May 2017 13:30:33 +0000</pubDate>
      <dc:creator>SaintPepsi</dc:creator>
      <guid isPermaLink="false">22739@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I'm trying to find a way around this problem where when I get more than 5 touches in the touch array the canvas seems to freeze until I take all touches off and touch with one finger again.</p>

<p>The code i'm using:</p>

<pre><code>    var touchesDown = 0;
    touchesDown = touches.length;
    text(touchesDown, width/2,height/2);
    for (var i = 0; i &lt; touches.length; i++) {
      text(touches[i].x.toFixed(2) + ", " + touches[i].y.toFixed(2), touches[i].x, touches[i].y - 50);
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>What's causing the Array index out of bounds error?</title>
      <link>https://forum.processing.org/two/discussion/19898/what-s-causing-the-array-index-out-of-bounds-error</link>
      <pubDate>Sat, 24 Dec 2016 10:33:42 +0000</pubDate>
      <dc:creator>duzbot</dc:creator>
      <guid isPermaLink="false">19898@/two/discussions</guid>
      <description><![CDATA[<p>I am a programming beginner and am unsure what may be causing error: ArrayIndexOutOfBoundsException: 2. I think it's either a logic error in the for loop or a syntax error with the array. Would anyone advise me with what is going wrong in the following code and how you might approach fixing an error like this. If I track the values on paper the numbers seem to be as i intended.</p>

<p>For reference I want the program to store p amount of grey colour values (plus black and white 0, 255) in an array. The values stored in the array occur at equal intervals. e.g p value of 5 should store:{ 0, 51, 102, 153, 204, 255 }.</p>

<p>Thanks for any help.</p>

<pre><code>int p = 1;
int interval = 255 / p;
int[] vGreyPalette = new int [(p+1)];

 void setup() {
   size(200, 200);
   noLoop();
 }

 void draw () {

  for (int i = 0; i == p; i++) {    
    vGreyPalette[i] =  (i * interval);
  }
  fill (vGreyPalette[int(random(p))]);
  rect(0, 0, width, height);

 }

void keyPressed() {
  if (key == 'w') {
    p = p + 1;
    redraw();
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>my for-loop skips a position</title>
      <link>https://forum.processing.org/two/discussion/18972/my-for-loop-skips-a-position</link>
      <pubDate>Thu, 10 Nov 2016 17:47:31 +0000</pubDate>
      <dc:creator>LuisLuethi</dc:creator>
      <guid isPermaLink="false">18972@/two/discussions</guid>
      <description><![CDATA[<p>i tried to adjust a slit scan video code to move the copy command from left to right through the video. that works, but in the output it skips a position, leaving a white strip between. how can i make the output dense?</p>

<pre><code>import processing.video.*;
Movie myMovie;
int pos;
int sliceSize = 5;
int outputcounter= 1;
String date;
void setup() {
  size(5000, 720);
  myMovie = new Movie(this, "versuch1.mp4");
  myMovie.loop();
  pos = 0;
  date = timestamp();
  //myMovie.jump(176);
}
void draw() {
  if (myMovie.available()) {
    myMovie.read();
    pushMatrix();
    for (int i=0; i&lt;1280; i+= sliceSize){
    //translate(width/2, height/2);
    //rotate(HALF_PI);
    //translate(-width/2, -height/2);
    //tint(255, 20);
    copy(myMovie, i, 0, sliceSize, myMovie.height, pos, 0, sliceSize, height); //(copy (quelle, x , y, breite, höhe, position im neuen bild, ))
    scale(-1,1);
    pos+=sliceSize*i; //horizontal gefilmt
    //copy(myMovie, 0, myMovie.height/2, myMovie.width, sliceSize, 0, pos, width, sliceSize); //vertical gefilmt
    //pos-=sliceSize;
    if (pos&gt;width) {
      saveFrame("png/"+ date+"/"+nf(outputcounter,3)+".png");
      outputcounter++;
      pos = 0;
    }
    }
    //image(myMovie, 0,0,960,540);}
    popMatrix();
  }
  }


// Called every time a new frame is available to read
/**void movieEvent(Movie m) {
 m.read();
 }*/

void keyPressed() {
  if (key == 32) {
    saveFrame("png/output_"+timestamp()+".png");
  }
}

String timestamp() {
  return new java.text.SimpleDateFormat("yyyy_MM_dd_kkmmss").format(new java.util.Date ());
}

//webseite 100vh quadrat (3/4=133) png= 001.png, 002.png
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to fix my finite loop?</title>
      <link>https://forum.processing.org/two/discussion/18549/how-to-fix-my-finite-loop</link>
      <pubDate>Fri, 14 Oct 2016 20:24:33 +0000</pubDate>
      <dc:creator>Nekios</dc:creator>
      <guid isPermaLink="false">18549@/two/discussions</guid>
      <description><![CDATA[<p>I want it to stop at 100 dots.</p>

<pre><code>float a;
float b;
int dotNumber = 0;
void setup() {
  size(200, 200);
  background(255);
}
void draw() {
  strokeWeight(3);
  a = random(200);
  b = random(200);
  dotNumber = 0;
  while(dotNumber &lt; 100) {
    point(a, b);
    dotNumber = dotNumber + 1;
    print(dotNumber);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Ability to store first and last value during the start and end of event</title>
      <link>https://forum.processing.org/two/discussion/18432/ability-to-store-first-and-last-value-during-the-start-and-end-of-event</link>
      <pubDate>Thu, 06 Oct 2016 14:32:30 +0000</pubDate>
      <dc:creator>ribvault</dc:creator>
      <guid isPermaLink="false">18432@/two/discussions</guid>
      <description><![CDATA[<p>Beginner here :)</p>

<p>This is is a part of code I plan to implement inside Class, so I've tried to avoid using void mousePressed(){} and instead create my own function, and yet it doesn't do what I would've expected it to do. So I tried to strip it to bare bones, and see what's up.</p>

<pre lang="processing"> 
    int R=1, A=255; //Ellipse radius and Alpha value
    IntList PosX = new IntList(1), PosY = new IntList(1); //Values placeholder
    int inPosX, inPosY, CountBegin, strength;
    IntList Count = new IntList(1);//Values placeholder
    
    void setup() {
      size(360, 360);
    }
    
    void draw() {
      background(51);
      if (mousePressed) {//Added if(){} so that I will only be able to enter the loop once I press the mouse button
                         //Because otherwise I fear It'll get executed once, record the value at index(0) at the start of the program
                         //The test will get evaluated as false and it'll exit the loop
        for (int i=0; mousePressed; i=1) {
          //My understanding was that the moment the event get triggered
          //The initial value will get placed at index (0), while the rest will get constantly updated at index (1)
          //until the test get evaluated as false, and event ends, but the values will get recorded.
          
          PosX.set(i, mouseX);   PosY.set(i, mouseY);    Count.set(i, millis());
          inPosX=PosX.get(0);    inPosY=PosY.get(0);     CountBegin=Count.get(0);
          
          fill( 0, 121, 184, A);
          ellipse(inPosX, inPosY, R, R);
          R++; 
          A=constrain(A--, 0, 255);
    
          strength=millis()-CountBegin;
        }
      }
      println(CountBegin);  //And this get's me 0.00's, but even if I place it inside if(){} or for(){}
                            //and tell it to print a predefined value, it won't even execute the command.
                            //Meaning it never executes those blocks of code
    }
    </pre>

<p><strong>Expectation:</strong> Inside the eventual working Class object, I'd announce it's variables as placeholders, with the press of the mouse button it'll 'charge' and display the progress of it's charging, record its charge strength, call the whole function <code>void born(){}</code>, upon release it'll pass the strength value to another block of code and execute, in the future, <code>void grow(){}</code>, the strength value would indicate for either how long it'll live or how big it'll be, so I thought I'd divide it's death in <code>void wither(){}</code>, where it'll fade and <code>void die(){}</code>, where I'd remove it from program.</p>

<p><strong>Reality:</strong> It just doesn't agree with me.</p>

<p>Seeing as I'm still stuck in the beginning stage I'm looking for help or any alternatives to perform same task of recording first instance of a value and it's last.</p>

<p>Thank you!</p>
]]></description>
   </item>
   <item>
      <title>What made my for loop point all the lines to the centre?</title>
      <link>https://forum.processing.org/two/discussion/18101/what-made-my-for-loop-point-all-the-lines-to-the-centre</link>
      <pubDate>Wed, 07 Sep 2016 12:47:37 +0000</pubDate>
      <dc:creator>Mattise19</dc:creator>
      <guid isPermaLink="false">18101@/two/discussions</guid>
      <description><![CDATA[<p>This isn't really a problem i'm having but i'd just like to understand better what's going on. Following the instructions in the book, i embedded two for loops into each other and gave them parametres that point the lines to centre, here's the code:</p>

<p><code>background(0);
 fill(255);
 stroke(102);
 for (int y = 20; y &lt;= height-20; y += 10) {
   for (int x = 20; x &lt;= width-20; x += 10) {
     ellipse(x, y, 4, 4);
     line(x, y, 240, 60);</code></p>

<p>Can someone please explain to me what causes the loops to point those lines from the ellipses to the centre specifically? Would just like know, thanks in advance!</p>
]]></description>
   </item>
   <item>
      <title>for loop</title>
      <link>https://forum.processing.org/two/discussion/18028/for-loop</link>
      <pubDate>Thu, 01 Sep 2016 10:01:11 +0000</pubDate>
      <dc:creator>phaidon</dc:creator>
      <guid isPermaLink="false">18028@/two/discussions</guid>
      <description><![CDATA[<p>hello,why this for loop is giving me null pointer exception?
Before Setup</p>

<pre><code>PVector PsVerts[] ;
PVector PsVerts2[]; 
</code></pre>

<p>In draw</p>

<pre><code>pushMatrix();
  rotateY(-k); //-----------------HERE
  translate(Mouse.x, Mouse.y, Mouse2.z+width/2);
  rotateY(k); //
  fill(26, 59, 45);
  beginShape();

  for (int i=0; i &lt; 800; i+=10 ) {
    println(i);
    PVector PsVerts[] = new PVector [i];
PVector PsVerts2[] = new PVector [i];
println(i);
   PsVerts[i].x = Mouse.x;
    PsVerts[i].y = Mouse.y ;

    PsVerts2[i].x = Mouse2.x;
    PsVerts2[i].y = Mouse2.y ;

    vertex(Mouse.x, Mouse.y, 0);
    vertex(Mouse2.x, Mouse2.y, 0);
  }
  endShape();
  popMatrix();
</code></pre>
]]></description>
   </item>
   <item>
      <title>Limited number of iterations in for loop/draw?!</title>
      <link>https://forum.processing.org/two/discussion/16434/limited-number-of-iterations-in-for-loop-draw</link>
      <pubDate>Thu, 05 May 2016 07:36:31 +0000</pubDate>
      <dc:creator>DanObscur</dc:creator>
      <guid isPermaLink="false">16434@/two/discussions</guid>
      <description><![CDATA[<p>I have a code that draws a line inside a for loop in <code>void draw()</code> and it works fine, until the number of iterations of the loop times the number of frames equals 25,000,000. Then the line displays incorrectly. For example:</p>

<p>Using <code>for (int i=0; i&lt;=5000; i++)</code> it stops displaying correctly at <code>FrameCount = 5000</code> (5,000 * 5,000 = 25,000,000).</p>

<p>Using <code>for (int i=0; i&lt;=10000; i++)</code> it stops displaying correctly at <code>FrameCount = 2500</code> (10,000 * 2500 = 25,000,000).</p>

<p>Using <code>for (int i=0; i&lt;=50000; i++)</code> it stops displaying correctly at <code>FrameCount = 500</code> (50,000 * 500 = 25,000,000).</p>

<p>Is there a way to just keep it running properly? Thanks.</p>
]]></description>
   </item>
   <item>
      <title>Error - Mapping value affects the other values</title>
      <link>https://forum.processing.org/two/discussion/15222/error-mapping-value-affects-the-other-values</link>
      <pubDate>Tue, 01 Mar 2016 10:12:17 +0000</pubDate>
      <dc:creator>blyk</dc:creator>
      <guid isPermaLink="false">15222@/two/discussions</guid>
      <description><![CDATA[<p>I have been mapping to write a code when I stumble upon this problem. Here in the code, line 11, I am mapping the i from 2-7 --&gt; 0, 50 for R. Ideally this mapping shouldn't affect the value of i but it is affecting.</p>

<p><strong>The problem</strong> -&gt; when I map i from 0-7 it works and the letter "A" doesn't rotate but when I map i from 2-7 it affects the value of i and "C" is the letter which doesn't rotate, ideally it should be "A" no matter how do I map i for R</p>

<pre><code>    String[] s = {
      "A", "B", "C", "D", "E", "F", "G"
    };  
    void setup() {
      size(300, 300);
    }
    int k=0;
    void draw() {
      background(-1);
      for (int i=0; i&lt;7; i++) {
        float R = map(i, 2, 7, 0, 50);
        float ang = i*360/7;
        float x = width/2+R*cos(radians(ang)+radians(k));
        float y = height/2+R*sin(radians(ang)+radians(k));
        // println(i);
        //    if (i&lt;4) {
        fill(0);
        text(s[i], x, y);
        //    } else {
        //      fill(0);
        //      ellipse(x, y, 5, 5);
        //    }
      }
      k++;
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>A float behaves like an int-value</title>
      <link>https://forum.processing.org/two/discussion/13410/a-float-behaves-like-an-int-value</link>
      <pubDate>Thu, 05 Nov 2015 16:22:15 +0000</pubDate>
      <dc:creator>injuvik</dc:creator>
      <guid isPermaLink="false">13410@/two/discussions</guid>
      <description><![CDATA[<p>Hi Coders!</p>

<p>I am trying to make my program draw lines, that become just a little bit thicker each step. But: The sketch does not react to my decimal numbers. I want to have a gradient in the strokeWeight of my lines. Is this possible?</p>

<pre><code>void setup () {
  size(540, 540);
  background(0);

  fill(255;
}

void draw() {
  background(0);
  noStroke();

  for (float i = 0; i &lt; a; i++) {
rect(width-i*10,0,i/20,height);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to create Iterate-Through-Edges feature for a game of life program?</title>
      <link>https://forum.processing.org/two/discussion/13396/how-to-create-iterate-through-edges-feature-for-a-game-of-life-program</link>
      <pubDate>Wed, 04 Nov 2015 03:09:57 +0000</pubDate>
      <dc:creator>kennyLiao</dc:creator>
      <guid isPermaLink="false">13396@/two/discussions</guid>
      <description><![CDATA[<p><a href="/two/profile/quark">@quark</a></p>

<p>Hi everyone,  I am trying to build <a rel="nofollow" href="https://github.com/EmbraceLife/myGOLexplorer"><strong>a game of life application</strong></a> with many useful features . For latest detail, please check the latest branch. (there are too many keys to operate, so I made a <a rel="nofollow" href="https://www.youtube.com/watch?v=vvQlu-O3ASs"><em>video for a non-programmer friend to try</em></a>)</p>

<p>While reading <a href="/two/profile/quark">@quark</a>'s <a rel="nofollow" href="http://www.lagers.org.uk/"><strong>website</strong></a>, I noticed the game of life app can moving over edge and appear from the other side. I thought it should not be very hard to write but I was wrong and it is driving me crazy.</p>

<p>I guess the tricky part is handing when <code>xx == -1</code> and <code>xx == (width-1)/cellSize</code> and <code>yy == -1</code> and <code>yy == (width-1)/cellSize</code> and xx yy being neighbour cell's coordinates. Below is the <code>iteration</code> function I tried to create going through-edges feature.</p>

<p>Could you help me with this feature? Thanks!</p>

<p>In the latest branch, there are two iteration functions one named <code>iteration()</code>(the driving me crazy one, below) and <code>iterationOld()</code>(the working one but without going through-edges feature) :</p>

<p>This <code>iteration()</code> appears with no error, but it disabled previously working program.</p>

<pre><code>    //(here are some of the global variables)
    // cell is a rect with width and height both 5 pixels
    int cellSize = 5;

    // canvas is carved into a grid named cells and cellsBuffer (for memory)
    int[][] cells; 
    int[][] cellsBuffer;

    // canvas's width and height deliberately set as 601 which helps me display a selecting red square when it aligns with edges
    int width =  601;
    int height =601; 


        void iteration() { 


         // save cells to cellsBuffer before every iteration
         for (int x=0; x&lt;(width-1)/cellSize; x++) {
           for (int y=0; y&lt;(height-1)/cellSize; y++) {
             cellsBuffer[x][y] = cells[x][y];
           }
         }

         // for every cell
         for (int x=0; x&lt;(width-1)/cellSize; x++) {
           for (int y=0; y&lt;(height-1)/cellSize; y++) {

             // number of its neighbours set 0 at first
             int neighbours = 0; 

             // loop around each cell to count up its living neighbours
             for (int xx=x-1; xx&lt;=x+1; xx++) { //&lt;&gt;// //&lt;&gt;//

               if (xx == (width-1)/cellSize) {
                 xx = 0;
               }

               if (xx == -1) {
                 xx = (width-1)/cellSize-1;
               }

               for (int yy=y-1; yy&lt;=y+1; yy++) {  

                 if (yy == -1) {
                   yy = (height-1)/cellSize-1;
                 }
                 if (yy == (height-1)/cellSize) {
                   yy = 0;
                 }

                   if (!((xx==x)&amp;&amp;(yy==y))) { 
                     // if a neighbour's value is 1, set count it as 1
                     if (cellsBuffer[xx][yy]==1) { 
                       neighbours ++; //&lt;&gt;// //&lt;&gt;//
                     }
                   }
                 //}
               }
             }



             // ***** apply rules to each cell

             // if it is alive, but living neighbours are less than 2 or more than 3, make it dead
             if (cellsBuffer[x][y]==1) { 
               if (neighbours &lt; 2 || neighbours &gt; 3) { 
                 cells[x][y] = 0;
               } else {
                 // nothing changes
               }
             } else { // if it is dead 

               // but if its living neighbour are exactly 3, then make it alive
               if (neighbours == 3 ) { 
                 cells[x][y] = 1;
               } else {
                 // nothing changes
               }
             }
           }
         }
        }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Replacing an array of strings with integer</title>
      <link>https://forum.processing.org/two/discussion/13178/replacing-an-array-of-strings-with-integer</link>
      <pubDate>Thu, 22 Oct 2015 16:12:49 +0000</pubDate>
      <dc:creator>yousufalin</dc:creator>
      <guid isPermaLink="false">13178@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I have an array of Strings, {a,b,c,b,a,d,a,c,a}. I wanted to sort and replace them with integers, and change it as {0,1,2,1,0,3,0,2,0}</p>

<p>As the first step I tried removing the repeating elements from the array and made another array of strings {a,b,c,d}. 
Then I used a for loop and assigned values for these strings as {0,1,2,3}.</p>

<p>Now I wanted to replace the individual members in the first array of strings, where "a" is replaced with "0", "b" with "1", "c " with "2" and "d" with "3", and make an array {0,1,2,1,0,3,0,2,0}</p>

<pre><code>String [] name = {"a", "b", "c", "b", "a", "d", "a", "c", "a"};

IntDict sortedName;
IntDict finalNameList;


void setup() {
  size(600, 600);
  smooth();

  sortedName = new IntDict();
  finalNameList = new IntDict();


  for (int i=0; i&lt;name.length; i++) {
    finalNameList.increment(name[i]);
  }

  String [] names = sortedName.keyArray(); //// sorted array of strings {a,b,c,d}

  for (int i=0; i&lt;names.length; i++) {
    finalNameList.set(names[i], i);
  }

  int [] values = finalNameList.valueArray(); ///// assigned values for a,b,c,d-- 0,1,2,3


  ////// now i wanted to replace the strings in the first array, name with the integers

  for (int i =0; i&lt;name.length; i++) {
    name[i]= name[i].replaceAll(names[i], i-names.length);

    println(name[i]);
  }
}


void draw() {

  background(125);
}
</code></pre>

<p>would be great if someone can help me with this. 
many thanks in advance :)</p>
]]></description>
   </item>
   <item>
      <title>finding the sum of numbers in an array.</title>
      <link>https://forum.processing.org/two/discussion/13021/finding-the-sum-of-numbers-in-an-array</link>
      <pubDate>Wed, 14 Oct 2015 21:50:17 +0000</pubDate>
      <dc:creator>yousufalin</dc:creator>
      <guid isPermaLink="false">13021@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone,</p>

<p>I was trying to find the sum of an array of numbers. but when i tried calculating it using the code below, I found the values being continuously increased since the forloop is running. Is there any way that I can get the sum of the numbers in the array other than adding a noLoop function or doing the addition inside void setup?</p>

<p>It would be a great help if someone can help me with this. Many thanks in advance</p>

<p>Cheers,
Yousuf.</p>

<pre><code>    float sum = 0;
    float [] f = {12, 2, 4, 6, 23};

    void setup() {

      size(600, 600);
      smooth();
    }

    void draw() {

      for (int i =0; i&lt;f.length; i++) {

        sum +=f[i];
      }
      println(sum);//// I only wanted to print the first value of sum, which is the total of the numbers listed array of numbers.
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Arrange many lines around a circle</title>
      <link>https://forum.processing.org/two/discussion/12226/arrange-many-lines-around-a-circle</link>
      <pubDate>Sun, 23 Aug 2015 17:46:35 +0000</pubDate>
      <dc:creator>injuvik</dc:creator>
      <guid isPermaLink="false">12226@/two/discussions</guid>
      <description><![CDATA[<p>Hi Coders!</p>

<p>I want to arrange many lines around a circle in Processing. The amount of lines shall be controlled by the mouseX-position. But i struggle with that:</p>

<ol>
<li><p>I want the lines to be arranged around the circle properly. The angle/gap between the lines shall be equal. But there's a gap between the first and the last line.</p></li>
<li><p>I try to get familiar with the map()-function but it does not work.</p></li>
</ol>

<p>Thank you guys!!!!</p>

<p>Here's my code:</p>

<pre><code>int a;

void setup () {
  size(540, 540);
  background(#222222);
  stroke(#dddddd);
  noFill();
}

void draw() {
  a = mouseX;
  map(a,0,width,0,100);
  background(#222222);
  translate(width/2, height/2);
  ellipse(0,0,100,100);
  for (int i = 0; i &lt; a; i++) {
    rotate(radians(360/a)); 
    line(50, 0, 200, 0);
  }
  println(a);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How do I make a grid of objects?</title>
      <link>https://forum.processing.org/two/discussion/11793/how-do-i-make-a-grid-of-objects</link>
      <pubDate>Wed, 22 Jul 2015 15:12:42 +0000</pubDate>
      <dc:creator>shadowrokx</dc:creator>
      <guid isPermaLink="false">11793@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I'm new to processing and I'm trying to create a grid of rectangles that flash different colors at random intervals.</p>

<p>Here's my code:</p>

<pre><code>int size = 300;
int tileSize = 15;
int tileNumber = size / tileSize;
tile [] tileField = new tile [tileNumber];

void setup() {
  size(size, size);
  for (int i = 0; i &lt; tileNumber; i++) {
    for (int j = 0; j &lt; tileNumber; j++) {
      tileField[i] = new tile(i * tileSize, j * tileSize, 255, 255, 255, 5);
    }
  }
}

void draw() {
  background(0);
  for(int i = 0; i &lt; tileNumber; i++) {
    tileField[i].tileRun();
  }
}

class tile {
 int tileX;
 int tileY;
 int tileRed;
 int tileGreen;
 int tileBlue;
 int tileActive;

 tile(int _tileX, int _tileY, int _tileRed, int _tileGreen, int _tileBlue, int _tileActive) {
   tileX = _tileX;
   tileY = _tileY;
   tileRed = _tileRed;
   tileGreen = _tileGreen;
   tileBlue = _tileBlue;
   tileActive = _tileActive;
 }

 void tileRun() {
   tileDisplay();
   tileActivate();
 }

 void tileDisplay() {
   fill(tileRed, tileGreen, tileBlue);
   rect(tileX, tileY, tileSize, tileSize);
 }

 void tileActivate() {
   tileActive = int(random(501));
   if (tileActive == 0) {
     tileRed = int(random(256));
     tileGreen = int(random(256));
     tileBlue = int(random(256));
   }
   else {
     tileRed = 0;
     tileGreen = 0;
     tileBlue = 0;
   }
 }
}
</code></pre>

<p>However when I run the code only the squares on the bottom of the screen flash. Is it a problem with my forLoop?</p>
]]></description>
   </item>
   <item>
      <title>Do I need a PShape GROUP?</title>
      <link>https://forum.processing.org/two/discussion/11814/do-i-need-a-pshape-group</link>
      <pubDate>Thu, 23 Jul 2015 20:55:49 +0000</pubDate>
      <dc:creator>eljusticiero</dc:creator>
      <guid isPermaLink="false">11814@/two/discussions</guid>
      <description><![CDATA[<p>Sorry if this has been answered in another post, n00b city over here. I want an array of PShape objects all to follow mouseX and mouseY. However, when I try to use translate(mouseX,mouseY) within the for loop that displays the objects, instead of all drawing at the mouse position, they move with the mouse but are offset. I know this has to do with the for loop, but can't figure out why. Do I need to getVertex on each of these and move each vertex using add()? Do I need separate pShapes? Is it a problem with trying to use translate() with an array? Hopefully someone will point out the obvious :-D. P.S. I know the name of my class is Square and i'm drawing stars.</p>

<pre><code>Square[] theSquares;
void setup(){
size(500,500,P2D);
theSquares = new Square[4];
for (int i=0;i&lt;=theSquares.length -1; i++){
  theSquares[i] = new Square();
  }
}

void draw(){
background(255);

for (int s=0;s&lt;=(theSquares.length-1);s++){
  theSquares[s].display();
  theSquares[s].moveSquare();
}
}

class Square {
  PShape coolShape;
  int x;
  int y;

 //constructor
 Square(){
  coolShape = createShape();
  coolShape.beginShape();
  coolShape.noStroke();
  coolShape.fill(0, 127);
  coolShape.vertex(0, -50);
  coolShape.vertex(14, -15);
  coolShape.vertex(47, -15);
  coolShape.vertex(23, 7);
  coolShape.vertex(29, 40);
  coolShape.vertex(0, 25);
  coolShape.vertex(-29, 40);
  coolShape.vertex(-23, 7);
  coolShape.vertex(-47, -15);
  coolShape.vertex(-14, -15);
  coolShape.endShape(CLOSE);
 }

 void moveSquare(){
   x=mouseX;
   y=mouseY;
   translate(x,y);
  }

 void display(){
   shape(coolShape);
 }
 }
</code></pre>
]]></description>
   </item>
   <item>
      <title>For Loops and Rotation</title>
      <link>https://forum.processing.org/two/discussion/11711/for-loops-and-rotation</link>
      <pubDate>Wed, 15 Jul 2015 21:49:31 +0000</pubDate>
      <dc:creator>skelatonne</dc:creator>
      <guid isPermaLink="false">11711@/two/discussions</guid>
      <description><![CDATA[<p>I have the following piece of code in my draw function. I want the line segments all to point towards the centre of the circle they create, rather than pointing directly downwards.</p>

<p>I've only been able to make the lines all rotate to the same degree. So, can someone explain how to make each line rotate +6 degrees each time? Thank you.</p>

<pre><code>  for(int i = 0; i &lt; 60; i++ ) {
    float xPos = 230 * sin(TWO_PI/60 * i);
    float yPos = 230 * cos(TWO_PI/60 * i);
    line(clockPos + xPos, clockPos + yPos, clockPos + xPos, clockPos + yPos + 10);
  }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Why the array doesn't work?</title>
      <link>https://forum.processing.org/two/discussion/11484/why-the-array-doesn-t-work</link>
      <pubDate>Sat, 27 Jun 2015 18:22:09 +0000</pubDate>
      <dc:creator>rickymarto</dc:creator>
      <guid isPermaLink="false">11484@/two/discussions</guid>
      <description><![CDATA[<p>Hello everybody, I'm new in Processing world andin the forum.</p>

<p>I'm doing some exercizes on Array and Loop.
In this example I want to draw 5 circles on along the same _y _direction and with a distance (150) between each other on the _x _axis.
I used the _for _loop to inizialize, I don't understand why the array doesn't work, there is just one circle, the first(0).</p>

<p>Could you tell me what's wrong with the code?</p>

<pre><code> //array vuoto di 4
 Cerchio[] cr =new Cerchio[4];



  void setup () {
  background(0);

  size(750, 500);


   //createtheobject and populate it in the array
  float dist;
  float dim=100;
  float y=350;

  for (int i=0; i&lt;cr.length; i++) {
   cr[i]=new Cerchio(150,250, dim);
  }
}
</code></pre>

<p>void draw() {</p>

<pre><code>  //iterate throught th
 for (int i=0; i&lt;cr.length; i++) {
   cr[i].display();
 }
}
</code></pre>

<p>//tab</p>

<pre><code>class Cerchio {
 float x;
 float y;
 float dim;

 Cerchio(float _x, float _y, float _dim) {

   x=_x;
   y=_y;
   dim=_dim;
 }



 void display() {


  for (int i=0; i&lt;cr.length; i++) {
    noStroke();
    smooth();
    fill(255, 255);
    ellipse(x, y, dim, dim);
  }
 }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to delay with millis()/loop</title>
      <link>https://forum.processing.org/two/discussion/11479/how-to-delay-with-millis-loop</link>
      <pubDate>Sat, 27 Jun 2015 15:28:57 +0000</pubDate>
      <dc:creator>sectra</dc:creator>
      <guid isPermaLink="false">11479@/two/discussions</guid>
      <description><![CDATA[<p>Hi there,
I'm new to Processing and currently working on a project that uses the mic input. So, as you rise the volume, a certain message would show up on the display. Now I want the last message to show up a little longer (let's say for 10 sec), before the draw function loops again. Tried a boolean function, which either ends in noLoop (if true) or it switches right back to the first message (if right).
Already googled a whole lot of different option, still did't find a good solution for my problem, yet.
I'd really appreciate some help!</p>

<p>
import ddf.minim.spi.*;<br />
import ddf.minim.signals.*;<br />
import ddf.minim.*;<br />
import ddf.minim.analysis.*;<br />
import ddf.minim.ugens.*;<br />
import ddf.minim.effects.*;<br />
import ddf.minim.*;
</p>

<p>
int time = millis();<br />
int timeLoop = 10000;
</p>

<p>
Minim minim;<br />
AudioInput in;<br />
float smoothingAlpha = 0.9;<br />
float smoothMicrophoneValue = 0;<br /> 
float microphoneLimit = 0.0367;<br />
float microphoneThreshold = 0.0001;<br />
PFont myFont;
</p>

<p>//----------------------------------------------------------------</p>

<p>
void setup(){<br />
   size(350, 500); <br />
   minim = new Minim(this); // Mikrofon<br />
    // use the getLineIn method of the Minim object to get an AudioInput<br />
    in = minim.getLineIn();<br />
 }
</p>

<p>//----------------------------------------------------------------</p>

<p>
void draw(){<br />
  frameRate(10);<br />
  background(#ED2D2D);<br /></p>

<p>float microphoneValue = in.left.get(0);<br />
  microphoneValue = abs(microphoneValue);<br />
  microphoneValue = smoothMicrophoneValue = smoothingAlpha * smoothMicrophoneValue + (1-smoothingAlpha) *<br />   microphoneValue;
</p>

<p>//----------------------------------------------------------------</p>

<p>
if(microphoneValue*18 &lt;= 2){&lt;br&gt;
  myFont = createFont("Apercu-Bold", 32);<br />
  textFont(myFont);<br />
  textAlign(CENTER, CENTER);<br />
  text("say it to me", width/2, 225);<br />
  }
</p>

<p>//----------------------------------------------------------------</p>

<p> 
if((microphoneValue*18 &gt; 2)&amp;&amp;(microphoneValue*18 &lt; 5)){<br /> 
  myFont = createFont("Apercu-Bold", 32);<br />
  textFont(myFont);<br />
  textAlign(CENTER, CENTER);<br />
  text("louder!", width/2, 225);<br />
}
</p>

<p>//----------------------------------------------------------------</p>

<p>
if(microphoneValue*18 &gt; 5){<br /> 
  time = 0;<br />
  println(millis());<br />
  boolean b = millis() &lt; timeLoop;<br />
  if(b == true) {<br />
    println("noLoop " + millis());<br />
    noLoop();}<br />
  if(b==false){<br />
        println("loop " + millis());<br />
    loop();}<br />
  myFont = createFont("Apercu-Bold", 32);<br />
  textFont(myFont);<br />
  textAlign(CENTER, CENTER);<br />
  text("hell yeah!", width/2, 225);<br />
  }<br />
 }
</p>
]]></description>
   </item>
   <item>
      <title>math operation not working with each iteration of for loop</title>
      <link>https://forum.processing.org/two/discussion/11340/math-operation-not-working-with-each-iteration-of-for-loop</link>
      <pubDate>Mon, 15 Jun 2015 22:17:26 +0000</pubDate>
      <dc:creator>markhirsch</dc:creator>
      <guid isPermaLink="false">11340@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to write a for loop that will layer images from an array and decrease the opacity of the next image with each new iteration in a particular way... (opLevel = (1/(j+1))*255). 
However, the operation doesn't seem to be working. Printing opLevel shows zeros for each iteration when it should be 255, 128, etc. Am I missing something? (the parts of code that would draw on my image files have been commented out to avoid errors)</p>

<pre><code>PImage[] img = new PImage[17];

int i;
int j;

float opLevel;

void setup() {
  size(1280, 720);

/*
  for (i=0; i &lt; img.length; i++) {    
    img[i] = loadImage(i + ".jpg");
  }
*/

  for (j = 0; j &lt; img.length; j++) {   

    opLevel = (1/(j+1))*255;
    tint(255, opLevel);
    //image(img[j], 0, 0);

    println(opLevel);
  }

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>The mythical "for" statements for noob like me...</title>
      <link>https://forum.processing.org/two/discussion/11232/the-mythical-for-statements-for-noob-like-me</link>
      <pubDate>Tue, 09 Jun 2015 12:54:36 +0000</pubDate>
      <dc:creator>PlzHelp</dc:creator>
      <guid isPermaLink="false">11232@/two/discussions</guid>
      <description><![CDATA[<p>What bothers me is the way how " for" statements are handled in nested iterations :</p>

<pre><code>for (float x = 0 ; x&lt; 400 ; x+= 40) {
    for (float y = 0 ; y&lt; 400 ; y+= 40){
        shape
    }
}
</code></pre>

<p>I seem not to understand how the " for" starts</p>

<p>thus these mean that for  every x becoming +40 it will create first y up to y 400 ? or</p>

<p>it has no sequence ?   also how is the structure would be created  if I added an inclining number after the encapsulated inclination ?</p>

<p>}
insert something here with inclining variable the affect the shape in the encapsulated "for' structure
}</p>

<p>what technique do you guys use to make using for iterations  easy to predict the results ?</p>

<p>also is it possible to make many for inside for ?</p>
]]></description>
   </item>
   <item>
      <title>I am trying to make the fish move....</title>
      <link>https://forum.processing.org/two/discussion/11223/i-am-trying-to-make-the-fish-move</link>
      <pubDate>Tue, 09 Jun 2015 00:42:00 +0000</pubDate>
      <dc:creator>lolnyancats</dc:creator>
      <guid isPermaLink="false">11223@/two/discussions</guid>
      <description><![CDATA[<pre><code>PImage fishImage, booty;
int q=1;
int p=1;

void setup() {
  size(600, 600);
  background(#124FB4);
}
void draw() {
  ArrayList&lt;Fish&gt; fish=new ArrayList();
  fishImage=loadImage("fish.jpg"); //load the image
  booty=loadImage("booty.jpg");
  if (q==1) {
    for (int i=0; i&lt;6; i++) {  // yes i know it would have been simpler to put this in the setup() method but i do not like simple... :)
      int x=int(random(width/5, width-50)); //x of fish
      int y=int(random(height/5, height-50)); //y of fish
      fish.add(new Fish(x, y));
      println(i);
      fill(#1203FF);
      stroke(#15D3D2);
      ellipse(x-15, y-5, 5, 5);
      ellipse(x-20, y-20, 5, 5);
      ellipse(x+5, y-45, 5, 5);
      q=2;
    }
    image(booty, int(random(50, width-50)), height-75, 50, 50);
  }
  if (p==1) {
    for (int i=0; i&lt;1000; i++) { //draw rocks as ellipses
      int x=int(random(width));
      int y=int(random(height-25, height));
      noStroke();
      int w=int(random(5));


      //if w==0 then it will fill the color of bubbles
      if (w==1)
        fill(#37EA1C);
      if (w==2)
        fill(#FFEB08);
      if (w==3)
        fill(#08F9FF);
      if (w==4)
        fill(#FF0808);
      if (w==5)
        fill(#FF08B9);

      ellipse(x, y, 10, 10);
      p=2;
    }
  }
  for (int i=0; i&lt;fish.size (); i++) {
    fish.get(i).display();
  }
  for (int i=0; i&lt;fish.size (); i++) {
    fish.get(i).move();
  }
}

class Fish {
  private int x, y;
  public Fish(int xpos, int ypos) {
    x=xpos;
    y=ypos;
  }
  void display() {
    image(fishImage, x, y, width/15, height/15);
  }
  void move() { //this is the stuff that is not executing correctly. i want it to constantly increase x but it is not increasing x at all....
    x+=5;
    if (x&gt;width) {
      x=0;
      println(x);
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>click on particle - loop over each?</title>
      <link>https://forum.processing.org/two/discussion/10549/click-on-particle-loop-over-each</link>
      <pubDate>Tue, 28 Apr 2015 01:16:30 +0000</pubDate>
      <dc:creator>argdev173</dc:creator>
      <guid isPermaLink="false">10549@/two/discussions</guid>
      <description><![CDATA[<p>Hi! I've a canvas with 400 aprox. elements (objects), each has a boolean state and i want to change that state by clicking on that object, i can achieve it by doing a dist from object x and y to mouse position. But looping over all the objects each time i click is a good choice? i think thats a perfomance flaw, i didnt try yet, but maybe in the future i want 1000 particles. The elements dont move, sorry for the english.</p>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>For Loop That Accesses Every Third Vertex?</title>
      <link>https://forum.processing.org/two/discussion/10562/for-loop-that-accesses-every-third-vertex</link>
      <pubDate>Tue, 28 Apr 2015 18:33:54 +0000</pubDate>
      <dc:creator>bretm9</dc:creator>
      <guid isPermaLink="false">10562@/two/discussions</guid>
      <description><![CDATA[<p>Basically I want to make a for loop that accesses every third (or whatever number) vertex and creates PVectors that I can multiply so I can deform them, in the same manner that I deformed my "p" PVector using mult(). I just don't know how to write a for loop to access those verts. Thanks for any help!</p>

<pre><code>// Copywrite Bret Merritt, 2015
PShape objShape;
float rotX;
float rotY;

void setup() {
  size(1280, 768, P3D);
  objShape = loadShape("Wolf_fixed.obj");
  stroke(200);
  strokeWeight(.7);
  smooth(8);
}

void draw() {
  stroke(200);
  background(20);
  translate(width/2, height/1.7, 300);
  rotateX(PI);
  rotateY(rotX);

  PShape s = createShape();
  s.beginShape(TRIANGLES); 
  for (int i=0; i&lt;objShape.getChildCount (); i++) {
    if (objShape.getChild(i).getVertexCount() ==3) {
      for (int j=0; j&lt;objShape.getChild (i).getVertexCount(); j++) {

        PVector p = objShape.getChild(i).getVertex(j);

        // random deform
        p.mult(random(.95, 1.05));

       // random fill per triangle 
//        s.fill(random(0, 200));

        s.vertex(p.x, p.y, p.z);
      }
    }
  }

  s.endShape(CLOSE);
  shape(s);
}

void mouseDragged() {
  rotX += (mouseX - pmouseX) * 0.01;
  rotY -= (mouseY - pmouseY) * 0.01;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Average all X Values of a PShape?</title>
      <link>https://forum.processing.org/two/discussion/10532/average-all-x-values-of-a-pshape</link>
      <pubDate>Mon, 27 Apr 2015 03:46:46 +0000</pubDate>
      <dc:creator>bretm9</dc:creator>
      <guid isPermaLink="false">10532@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to find the approximate center of my 3d PShape. 
I think to find said vertex, I'd need to average all the x coordinates, average all the y coordinates, and average all the z coordinates to get the center x y z.
How would I write a for loop that does this?</p>
]]></description>
   </item>
   <item>
      <title>help with simple ellipse game</title>
      <link>https://forum.processing.org/two/discussion/10206/help-with-simple-ellipse-game</link>
      <pubDate>Mon, 06 Apr 2015 12:37:09 +0000</pubDate>
      <dc:creator>jennymadison91</dc:creator>
      <guid isPermaLink="false">10206@/two/discussions</guid>
      <description><![CDATA[<p>Hello fellow processing gurus and masterminds!</p>

<p>It's my first time doing coding so I am having quite the struggle to come up with a simple game for my little project that I'm working on :( I do apologize if similar coding has been explained before... waahhhhh</p>

<p>The coding so far shows circles falling down from the top (that's the extend of my skills..), I would like the user to be able to click on it before it falls to the bottom, and the circle would disappear when clicked. If the circles reaches the bottom without it being clicked, the game finishes.. I know I'm suppose to use the forloop but it didn't work for me..</p>

<p>This is my code so far, I'd totally be eternally grateful if I get any help &lt;33</p>

<p>xx</p>

<p>int speed =2;
int posX =250;
int posY =0;</p>

<p>int posN =450;
int posM =0;</p>

<p>int posA =100;
int posB =0;</p>

<p>int posC =300;
int posD =-120;</p>

<p>int posE =200;
int posF =-40;</p>

<p>void setup(){
  size (500,500);</p>

<p>}</p>

<p>void draw(){
  background(0);</p>

<pre><code>ellipse(posX,posY,10,10);
</code></pre>

<p>if(posY &lt;600){
    posY = posY + speed+5;</p>

<p>}</p>

<pre><code>ellipse(posN,posM,20,20);
</code></pre>

<p>if(posM &lt;600){
    posM = posM + speed+5;
  }</p>

<pre><code>ellipse(posA,posB,30,30);
</code></pre>

<p>if(posA &lt;600){
  posB = posB + speed+3;
}</p>

<pre><code>ellipse(posC,posD,30,30);
if(posA &lt;600){
</code></pre>

<p>posD = posD + speed+3;
}
   ellipse(posE,posF,15,15);
    if(posA &lt;600){
  posF = posF + speed+3;
}
}</p>
]]></description>
   </item>
   <item>
      <title>How can you make a draw loop a specific amount of times?</title>
      <link>https://forum.processing.org/two/discussion/9565/how-can-you-make-a-draw-loop-a-specific-amount-of-times</link>
      <pubDate>Tue, 24 Feb 2015 16:49:01 +0000</pubDate>
      <dc:creator>RifleGirl</dc:creator>
      <guid isPermaLink="false">9565@/two/discussions</guid>
      <description><![CDATA[<p>I have a for loop and want it to create a random drawing 7 times without having to use:</p>

<p>void mousePressed() 
{
  loop();
  // Holding down the mouse starts the loop
}</p>
]]></description>
   </item>
   <item>
      <title>How to constrain a for loop draw to a specific area</title>
      <link>https://forum.processing.org/two/discussion/9560/how-to-constrain-a-for-loop-draw-to-a-specific-area</link>
      <pubDate>Tue, 24 Feb 2015 14:47:24 +0000</pubDate>
      <dc:creator>RifleGirl</dc:creator>
      <guid isPermaLink="false">9560@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to draw a bunch of objects in a constrained area, they are being translated so that they form interesting shapes together but I cannot figure out how to constrain these shapes to one area and not the entire screen.</p>
]]></description>
   </item>
   <item>
      <title>How to use array and for loop in my case?? please help</title>
      <link>https://forum.processing.org/two/discussion/9418/how-to-use-array-and-for-loop-in-my-case-please-help</link>
      <pubDate>Sat, 14 Feb 2015 04:39:20 +0000</pubDate>
      <dc:creator>chuckjai</dc:creator>
      <guid isPermaLink="false">9418@/two/discussions</guid>
      <description><![CDATA[<p>Hello guys, i am bad at english, hope you guys understand what i'm talking about.
I am working on my assignment of processing, i would like to create a mini game like NS SHAFT.
I want 3 object move from the bottom to the top,</p>

<p>in my code , obsX is the x position, obsY is y position:</p>

<p>obsX=int(random(-50, width-200));</p>

<p>obsY=height-100;</p>

<p>obsX2=int(random(-50, width-200));</p>

<p>obsY2=height+200;</p>

<p>obsX3=int(random(-50, width-200));</p>

<p>obsY3=height+400;</p>

<p>obsWidth=200;</p>

<p>obsHeight=100;</p>

<p>obsSpeed=5;</p>

<p>and i write a function call wood to make it move those objects upward:</p>

<p>void wood()
{</p>

<p>image(cloud,obsX, obsY, obsWidth, obsHeight);
  obsY=obsY-obsSpeed;</p>

<p>image(cloud,obsX2, obsY2, obsWidth, obsHeight);
  obsY2=obsY2-obsSpeed;</p>

<p>image(cloud,obsX3, obsY3, obsWidth, obsHeight);
  obsY3=obsY3-obsSpeed;</p>

<p>}</p>

<p>How could i use array and for loop to simplify the code??</p>
]]></description>
   </item>
   <item>
      <title>simple nested FOR loop: how to make a grid without using 'i &amp; j' as 'x &amp; y'?</title>
      <link>https://forum.processing.org/two/discussion/9310/simple-nested-for-loop-how-to-make-a-grid-without-using-i-j-as-x-y</link>
      <pubDate>Thu, 05 Feb 2015 20:09:54 +0000</pubDate>
      <dc:creator>gouvrit</dc:creator>
      <guid isPermaLink="false">9310@/two/discussions</guid>
      <description><![CDATA[<p>I know how to make a 10x10 grid of ellipses with FOR loops using the i &amp; j from loop as x &amp; y coordinates for the ellipses.</p>

<p>But I am trying to do the same ellipse grid, without using the i &amp; j's. Just using them as counters.
It works for one row of ellipses:</p>

<pre><code> size(200, 200);
 int x = 10;
 int y = 10;
 for (int i = 5; i &lt; width; i = i+10) { 
     ellipse(x, y, 10, 10);
     x = x+20;
    }
</code></pre>

<p>but when I try to do a grid (adding the nested for), it doesn't work.</p>

<pre><code> size(200, 200);
 int x = 10;
 int y = 10;

 for (int i = 5; i &lt; width; i = i+10) { 
   for (int j = 5; j &lt; height; j = j+20) {
     ellipse(x, y, 10, 10);
     x = x+20;
     }
     y = y+20; 
 }
</code></pre>

<p>And I can not see what I am missing. 
Anyone? 
thanks!</p>
]]></description>
   </item>
   </channel>
</rss>